package com.ruoyi.huanghefd.controller;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.huanghefd.domain.AttachsheetOs;
import com.ruoyi.huanghefd.domain.Makesheet;
import com.ruoyi.huanghefd.service.AttachsheetOsService;
import com.ruoyi.huanghefd.utils.PageBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author gnplum
 * @Date 2023/11/13 17:31
 * @PackageName:com.ruoyi.huanghefd.controller
 * @ClassName: AttachsheetOsController
 * @Description: TODO
 * @Version 1.0
 */
@RestController
@RequestMapping("/huanghefd")
public class AttachsheetOsController {

    private static final Logger log = LoggerFactory.getLogger(AttachsheetOsController.class);
    @Resource
    private AttachsheetOsService attachsheetOsService;

    /**
     * @param attachsheetOs
     * @return com.ruoyi.huanghefd.domain.ResultWS
     * http://localhost:8080/huanghefd/addAttachsheetOS
     * @Author gnplum
     * @Description //新增 作业安全风险控制卡
     * @Date 9:48 2023/11/11
     **/
    @PostMapping("/addAttachsheetOS")
    public AjaxResult addAttachsheetOS(@RequestBody AttachsheetOs attachsheetOs) {
        String in = JSON.toJSONString(attachsheetOs);
        log.info(">> 新增 作业安全风险控制卡-入参==" + in);
        AjaxResult ajax = attachsheetOsService.addAttachsheetOs(attachsheetOs);
        log.info("<< 新增 作业安全风险控制卡-返回==" + ajax.toString());
        return ajax;
    }

    /**
     * @param asCode
     * @return com.ruoyi.common.core.domain.AjaxResult
     * http://localhost:8080/huanghefd/delAttachsheetOS?asCode=4e60df22773811eeb08e00e04c738ae4
     * @Author gnplum
     * @Description //删除 作业安全风险控制卡
     * @Date 15:22 2023/11/11
     **/
    @PostMapping(value = "/delAttachsheetOS")
    public AjaxResult delAttachsheetOS(@RequestParam(required = false, value = "asCode") String asCode) {
        log.info(">> 删除作业安全风险控制卡-入参 asCode==" + asCode);
        if (asCode.isEmpty()) {
            return AjaxResult.success("请点选要删除的作业安全风险控制卡");
        }
        AjaxResult ajax = attachsheetOsService.delAttachsheetOs(asCode);
        log.info(">> 删除作业安全风险控制卡-返回==" + ajax);
        return ajax;
    }

    /**
     * @param attachsheetOs
     * @return com.ruoyi.common.core.domain.AjaxResult
     * http://localhost:8080/huanghefd/uptAttachsheetOS
     * @Author gnplum
     * @Description //修改 作业安全风险控制卡
     * @Date 15:47 2023/11/11
     **/
    @PostMapping(value = "/uptAttachsheetOS")
    public AjaxResult uptAttachsheetOS(@RequestBody AttachsheetOs attachsheetOs) {
        log.info(">> 修改 作业安全风险控制卡-入参 ==" + attachsheetOs);
        AjaxResult ajax = attachsheetOsService.uptAttachsheetOs(attachsheetOs);
        log.info(">> 修改 作业安全风险控制卡-返回 ==" + ajax);
        return ajax;
    }

    /**
     * @param asCode,asDept,asState
     * @return com.ruoyi.common.core.domain.AjaxResult
     * http://localhost:18080/huanghefd/queryAttachsheetOS?asCode=20231102000001
     * @Author gnplum
     * @Description //查询 作业安全风险控制卡
     * @Date 9:48 2023/11/11
     **/
    @PostMapping(value = "/queryAttachsheetOS")
    public AjaxResult queryAttachsheetOSList(@RequestParam(required = false, value = "asCode") String asCode, @RequestParam(required = false, value = "asState") String asState, @RequestParam(required = false, value = "userId") String userId, @RequestParam(required = false, value = "mailType") String mailType) {
        log.info(">> 查询作业安全风险控制卡-入参==" + asCode + "," + asState + "," + userId + "," + mailType);
        AjaxResult ajax = attachsheetOsService.queryAttachsheetOss(asCode, asState, userId, mailType);//mailType 1-收件箱 2-发件箱
        log.info(">> 查询作业安全风险控制卡-返回==" + ajax);
        return ajax;
    }

    /**
     * @param asCode
     * @param asState
     * @param userId
     * @param mailType
     * @param pageNum
     * @param pageSize
     * @return com.ruoyi.huanghefd.utils.PageBean
     * @Author gnplum
     * @Description //查询 作业安全风险控制卡 分页
     * @Date 16:16 2024/1/3
     **/
    @PostMapping(value = "/queryAttachsheetOS1")
    public PageBean queryAttachsheetOSList(@RequestParam(required = false, value = "asCode") String asCode, @RequestParam(required = false, value = "asState") String asState, @RequestParam(required = false, value = "userId") String userId, @RequestParam(required = false, value = "mailType") String mailType, @RequestParam(value = "pageNum") int pageNum, @RequestParam(value = "pageSize") int pageSize) {
        log.info(">> 查询作业安全风险控制卡-入参==" + asCode + "," + asState + "," + userId + "," + mailType);
        PageBean ajax = attachsheetOsService.queryAttachsheetOssByPage(asCode, asState, userId, mailType, pageNum, pageSize);//mailType 1-收件箱 2-发件箱 3-草稿箱
        log.info(">> 查询作业安全风险控制卡-返回==" + ajax);
        return ajax;
    }
}
